﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data;
using System.Web.UI;
using System.Web.UI.WebControls;
using Customer_Profile.eCard.DBDao;
using KVB.Common;
using System.IO;
using Customer_Profile.Admin;

namespace Customer_Profile.cardsite
{
    public partial class card_balance : System.Web.UI.Page
    {        
        public string cardbalance = "";
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                gridCflow.DataSource = null;
                gridCflow.DataBind();
            }
            this.Form.DefaultButton = "btnSearch";
        }

        protected void btnSearch_Click(object sender, EventArgs e)
        {
            //1,检查卡号是否存在，
            //2,检查卡号是否已经通过审查。
            //3,卡片是否被锁定。
            if (String.Compare(Request.Cookies["CheckCode"].Value, VCode.Text, true) != 0)
            {
                lblWaring.Text = "验证码错误!";
                txtCardBalance.Text = "";
                gridCflow.DataSource = null;
                gridCflow.DataBind();
            }
            else
            {
                string strCardNo = txtCardNo.Text.Trim();

                if (strCardNo.Equals(""))
                {
                    lblWaring.Text = "卡片号码不能为空！";
                }
                else
                {
                    bindTransfer();
                }
            }
        }

        protected void ChangeCode_Click(object sender, EventArgs e)
        {

        }

        private void bindTransfer()
        {
            try
            {
                string card_no = txtCardNo.Text.Trim();
                string id_no = txtIDNo.Text.Trim();
                string status = "";
                string message = "";
                DataSet ds = DealDao.CustomergetCardBalance(card_no,id_no,out status, out message);
                if (status.Equals("Y"))
                {
                    txtCardBalance.Text = double.Parse(ds.Tables[0].Rows[0]["card_balance"].ToString()).ToString("#,###.00");
                    //lblCpartyName.Text = ds.Tables[0].Rows[0]["cparty_name"].ToString();
                    cardbalance = ds.Tables[0].Rows[0]["card_balance"].ToString();
                    gridCflow.DataSource = ds.Tables[1];
                    gridCflow.DataBind();
                    lblWaring.Text = "";
                }
                else
                {
                    lblWaring.Text = message;
                    txtCardBalance.Text = "";
                    //lblCpartyName.Text = "";
                    gridCflow.DataSource = null;
                    gridCflow.DataBind();
                }
            }
            catch (Exception ex)
            {
                txtCardBalance.Text = "";
                //lblCpartyName.Text = "";                
                lblWaring.Text = ex.ToString();
                gridCflow.DataSource = null;
                gridCflow.DataBind();
            }
        }

        protected void gridCflow_PageIndexChanging(object sender, GridViewPageEventArgs e)
        {
            gridCflow.PageIndex = e.NewPageIndex;
            bindTransfer();
        }
    }
}